<?php
$base_path=str_replace('\\','/',dirname(__FILE__));

include_once( $base_path ."/dbconf.php");

function  get_menu_by_id($id){
	global $db;

	$list=$db->get_results(" select * from menu where id=$id ",true);
	if($list == false){
		return  false;
	}else{
		$db->debug();
		return  $list;
	}

}

function  get_menu(){
	global $db;

	$list=$db->get_results(" select * from menu where  menu_parent_id=0 ",true);
	if($list == false){
		return  false;
	}else{
		//$db->debug();
		return  $list;
	}
}

/**
 * list link url
 * Enter description here ...
 */
function  list_link(){
	global $db;

	$list=$db->get_results(" select * from  link  ",true);
	if($list == false){
		return  false;
	}else{
		foreach ($list as $linkItem) {
			echo "<li><a href=\"$linkItem->link_url\" target=\"_blank\" title=\"$linkItem->link_name\"><img src=\"$linkItem->link_picture\"";
			echo "border=\"0\"";
			echo "\"alt=\"$linkItem->link_name\" width=\"160\" /> </a></li>";
		}
			
	}
	return  $list;

}

/***
 * get menuItem by id
 */
function  get_menu_item_by_id($id,$parent_id){
	global $db;

	$list=$db->get_results(" select * from menu where  menu_parent_id=$parent_id ",true);
	if($list == false){
		return  false;
	}else{
		echo "<ul> \n";
		foreach ($list as $menu_item) {
			echo "\t<li> ";
			echo  "<span><a href=\"$menu_item->menu_url\">$menu_item->menu_name</a>" ;
			get_menu_item_by_id($menu_item->id,$menu_item->id);
			echo "\t</li></span>\n";
		}
		echo "</ul> \n\n";
	}
	return  $list;
}
/**
 * list menu all
 *
 */
function list_menu_all(){
	$list=get_menu();
	if($list!=false){
		echo "<ul id=\"nav_E8J8Zu\" class=\"navigation\">\n" ;
		foreach ($list as $menu_item) {

			echo " <li>\n";
			echo  "<span><a href=\"$menu_item->menu_url\">$menu_item->menu_name</a>" ;
			get_menu_item_by_id($menu_item->id,$menu_item->id);
			echo "\t</li></span>\n";
		}
		echo "</ul>\n";
	}
}

/***
 * get catlogid by id
 */
function  get_catlog_by_id($id){
	global $db;

	$list=$db->get_results(" select * from menu where id=$id ",true);
	if($list == false){
		return  false;
	}else{
		$db->debug();
		return  $list;
	}

}
/**
 *
 * Enter description here ...
 */
function list_home_page_product_pic(){
	global $db;

	$list=$db->get_results(" select id,product_desc,product_small_picture from product  where  show_as_scroll=1 ",true);
	if($list!=false){
		echo "<ul>\n" ;
		foreach ($list as $pic_item) {
			echo "<td><a href=\"view.php?typeId=$pic_item->id\" title=\"$pic_item->product_desc\"><img src=\"$pic_item->product_small_picture\" border=0 width=\"160\" height=\"120\" name=\"picautozoom\"></a></td>\n";
		}
	}
}

function list_home_page_product(){
	global $db;

	$list=$db->get_results("  select a.id,product_name, product_desc,product_small_picture ,product_catlog_id ,catlog_name  from product  a inner join catlog  b on
	   show_home_page=1 and  a.product_catlog_id=b.id; ",true);
	if($list!=false){
		echo "<ul>\n" ;

		foreach ($list as $item) {
			echo  "<div class=\"proItem\">";
			echo  "<div class=\"newprod_pic\"><a ";
			echo  " href=\"view.php?typeId=$item->id\" title=\"$item->product_desc\"><img ";
			echo  " name=\"picautozoom\" border=\"0\" src=\"$item->product_small_picture\"";
			echo  " class=\"prodthumb\" /> </a></div>";
			echo  "<div class=\"newprod_name\"><a";
			echo  "	href=\"view.php?typeId=$item->id\">$item->product_name</a></div>";
			echo  "<div class=\"newprod_intr\">分类: <a";
			echo  "	href=\"classic.php?typeId=$item->product_catlog_id\">$item->catlog_name</a></div>";
			echo  "<div class=\"blankbar1\"></div> ";
			echo  "</div>";
		}
	}
}

function list_product_by_catlog_id(){
	$catlog_id=intval( $_GET['typeId']);
	global $db;

	$list=$db->get_results("  select a.id,product_name, product_desc,product_small_picture ,product_catlog_id ,catlog_name  from product  a inner join catlog  b on
	  product_catlog_id=$catlog_id  and  a.product_catlog_id=b.id; ",true);
	if($list!=false){
		echo "<ul>\n" ;

		foreach ($list as $item) {
			echo  "<div class=\"proItem\">";
			echo  "<div class=\"newprod_pic\"><a ";
			echo  " href=\"\" title=\"$item->product_desc\"><img ";
			echo  " name=\"picautozoom\" border=\"0\" src=\"$item->product_small_picture\"";
			echo  " class=\"prodthumb\" /> </a></div>";
			echo  "<div class=\"newprod_name\"><a";
			echo  "	href=\"view.php?typeId=$item->id\">$item->product_name</a></div>";
			echo  "<div class=\"newprod_intr\">分类: <a";
			echo  "	href=\"classic.php?typeId=$item->product_catlog_id\">$item->catlog_name</a></div>";
			echo  "<div class=\"blankbar1\"></div> ";
			echo  "</div>";
		}
	}
}



function  get_catlog(){
	global $db;

	$list=$db->get_results(" select * from catlog  where   parent_id=0 ",true);
	if($list == false){
		return  false;
	}else{
		//$db->debug();
		return  $list;
	}
}

/***
 * get menuItem by id
 */
function  get_catlog_item_by_id($id,$parent_id){
	global $db;

	$list=$db->get_results(" select * from catlog where   parent_id=$parent_id ",true);
	if($list == false){
		return  false;
	}else{
		echo "<ul> \n";
		foreach ($list as $cat_item) {
			echo "\t<li> ";
			echo  " <a href=\"classic.php?typeId=$cat_item->id\">$cat_item->catlog_name</a>" ;
			get_catlog_item_by_id($cat_item->parent_id,$cat_item->id);
			echo "\t</li> \n";
		}
		echo "</ul> \n\n";
	}
	return  $list;
}
/**
 *
 * list catlog  all ...
 */
function list_catlog_all(){
	$list=get_catlog();
	if($list!=false){
		echo "<ul>\n" ;
		foreach ($list as $cat_item) {

			echo " <li>\n";
			echo  " <a href=\"classic.php?typeId=$cat_item->id\">$cat_item->catlog_name</a>" ;
			get_catlog_item_by_id($cat_item->parent_id,$cat_item->id);
			echo "\t</li> \n";
		}
		echo "</ul>\n";
	}
}

function list_product_by_id(){
	$id=intval( $_GET['typeId']);
	global $db;

	$list=$db->get_results("select a.id, c.product_content , a.product_name  ,product_catlog_id ,product_add_time ,catlog_name from product  a inner join catlog  b   on
	     a.product_catlog_id=b.id  inner join product_content  c   on  a.id= $id   ; ",true);
	if ( $list!=false){
		return $list[0];
	}else{
		return false;
	}
}

?>